<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="utf-8">
  <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
  
  <title>MySQL小结 | conor_hua</title>
  <meta name="description" content="辉夜大小姐想让我写博客。" />
  <meta name="keywords" content="Java,Sakura,spring" />
  
    <link rel="shortcut icon" href="https://cdn.jsdelivr.net/gh/conorhua/asset/ima/favicon00.ico">
  
  <meta http-equiv="x-dns-prefetch-control" content="on">
  <!--自定义看板娘-->
  <script src="https://cdn.jsdelivr.net/npm/jquery/dist/jquery.min.js"></script>
  <script src="/live2d-widget/autoload.js"></script>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/font-awesome/css/font-awesome.min.css"/>

  <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/xbclub/staticCDN@0.6/css/googlefont.css" media="all">
<!--  <link rel="dns-prefetch" href="//cdn.jsdelivr.net">-->
  <link rel="stylesheet" id="saukra_css-css" href="https://cdn.jsdelivr.net/gh/xbclub/staticCDN@0.6/css/style.css" type="text/css" media="all">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/xbclub/staticCDN@0.6/css/lib.min.css" media="all">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/xbclub/staticCDN@0.6/css/font.css" media="all">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/xbclub/staticCDN@0.6/css/insight.css" media="all">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/xbclub/staticCDN@0.6/css/jquery.fancybox.min.css" media="all">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/xbclub/staticCDN@0.6/css/zoom.css" media="all">
  <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/gh/xbclub/staticCDN@0.6/css/sharejs.css">
  <link rel="stylesheet" href="/css/tags.css" media="all">
  <!--   <link rel="stylesheet" id="saukra_css-css" href="https://2heng.xin/wp-content/cache/autoptimize/css/autoptimize_ad42a61f4c7d4bdd9f91afcff6b5dda5.css
" type="text/css" media="all"> -->
  <script>
  /*Initial Variables*/
  var mashiro_option = new Object();
  var mashiro_global = new Object();
  mashiro_option.NProgressON = true;
  /* 
   * 邮箱信息之类的东西可以填在这里，这些js变量基本都作用于sakura-app.js
   * 这样的设置仅是为了方便在基于PHP开发的主题中设置js变量，既然移植到了Node上，我想或许可以精简这一逻辑吧
   */
  mashiro_option.email_domain = "";
  mashiro_option.email_name = "";
  mashiro_option.cookie_version_control = "";
  mashiro_option.qzone_autocomplete = false;
  mashiro_option.site_name = "Conor_hua";
  mashiro_option.author_name = "";
  mashiro_option.site_url = "https://conor_hua.gitee.io";
  mashiro_option.v_appId = "GyC3NzMvd0hT9Yyd2hYIC0MN-gzGzoHsz";
  mashiro_option.v_appKey = "mgOpfzbkHYqU92CV4IDlAUHQ";
  mashiro_option.mathjax = "0";
  mashiro_option.qq_api_url = "https://api.mashiro.top/qqinfo/"; 
  mashiro_option.qq_avatar_api_url = "https://api.mashiro.top/qqinfo/";

  // mashiro_option.jsdelivr_css_src = "https://cdn.jsdelivr.net/gh/moezx/cdn@3.4.5/css/lib.min.css";
  // mashiro_option.float_player_on = true;

  /*End of Initial Variables*/
  </script>
  <script type="text/javascript">
  var bg = "https://cdn.jsdelivr.net/gh/conorhua/asset/ima/banner/6f005cbc1865ff1b706aba57347988ab.webp,https://cdn.jsdelivr.net/gh/conorhua/asset/ima/banner/ox83gp.jpg,https://cdn.jsdelivr.net/gh/conorhua/asset/ima/banner/a5fa4f9db760f58fc48f03d66b4967f7.webp,https://cdn.jsdelivr.net/gh/conorhua/asset/ima/banner/zm3vey.jpg,https://cdn.jsdelivr.net/gh/conorhua/asset/ima/banner/b3e8dae89b950b940dc0edd1e8cc0566.webp,https://cdn.jsdelivr.net/gh/conorhua/asset/ima/banner/j58y6y.jpg,https://cdn.jsdelivr.net/gh/conorhua/asset/ima/banner/4217z9.jpg,https://cdn.jsdelivr.net/gh/conorhua/asset/ima/banner/j5zg2p.jpg".split(",");
  var bgindex = Math.floor(Math.random()*bg.length);
  if (!!window.ActiveXObject || "ActiveXObject" in window) { //is IE?
    alert('朋友，IE浏览器未适配哦~');
  }
  </script>
  <style type="text/css">
  .hljs-ln{border-collapse:collapse}.hljs-ln td{padding:0}.hljs-ln-n:before{content:attr(data-line-number)}
  </style>
  <style type="text/css">.site-top .lower nav{display:block !important;}.author-profile i,.post-like a,.post-share .show-share,.sub-text,.we-info a,span.sitename,.post-more i:hover,#pagination a:hover,.post-content a:hover,.float-content i:hover{color:#FE9600}.feature i,.download,.navigator i:hover,.links ul li:before,.ar-time i,span.ar-circle,.object,.comment .comment-reply-link,.siren-checkbox-radio:checked + .siren-checkbox-radioInput:after{background:#FE9600}::-webkit-scrollbar-thumb{background:#FE9600}.download,.navigator i:hover,.link-title,.links ul li:hover,#pagination a:hover,.comment-respond input[type='submit']:hover{border-color:#FE9600}.entry-content a:hover,.site-info a:hover,.comment h4 a,#comments-navi a.prev,#comments-navi a.next,.comment h4 a:hover,.site-top ul li a:hover,.entry-title a:hover,#archives-temp h3,span.page-numbers.current,.sorry li a:hover,.site-title a:hover,i.iconfont.js-toggle-search.iconsearch:hover,.comment-respond input[type='submit']:hover{color:#FE9600}.comments .comments-main{display:block !important;}.comments .comments-hidden{display:none !important;}background-position:center center;background-attachment:inherit;}
  </style>
<script src="https://cdn.jsdelivr.net/gh/conorhua/asset/js/hititle.js"></script>
<meta name="generator" content="Hexo 4.2.1"></head>

<body class="page-template page-template-user page-template-page-analytics page-template-userpage-analytics-php page page-id-1297 chinese-font serif isWebKit">
  <div class="scrollbar" id="bar">
  </div>
  <a href="#" class="cd-top faa-float animated"></a>
  <section id="main-container">
    <div class="headertop filter-dot">
  <div id="banner_wave_1"></div>
  <div id="banner_wave_2"></div>
  <figure id="centerbg" class="centerbg">
    <div class="focusinfo no-select">
      <div class="header-tou">
        <a href="https://conor_hua.gitee.io" target="_blank" rel="noopener">
          <img src="https://cdn.jsdelivr.net/gh/conorhua/asset/ima/xiaomai.jpg">
        </a>
      </div>
      <div class="header-info">
        <p id="jinrishici-sentence">正在加载今日诗词....</p>
        <script src="https://sdk.jinrishici.com/v2/browser/jinrishici.js" charset="utf-8"></script>
        <div class="top-social_v2">
          <li id="bg-pre">
            <img class="flipx" src="https://cdn.jsdelivr.net/gh/honjun/cdn@1.6/img/other/next-b.svg">
          </li>
          
          
          
          <li>
            <a href="http://mail.qq.com/cgi-bin/qm_share?t=qm_mailme&amp;email=1_bi5eLm4_Tj4uGXpqb5tLi6" target="_blank" class="social-github" title="email">
              <img src="https://cdn.jsdelivr.net/gh/conorhua/asset/ima/email.png">
            </a>
          </li>
          
          
          
          <li class="wechat">
            <a href="/#">
              <img src="https://cdn.jsdelivr.net/gh/conorhua/asset/ima/wechat.png">
            </a>
            <div class="wechatInner">
              <img src="https://cdn.jsdelivr.net/gh/conorhua/asset/ima/1.jpg">
            </div>
          </li>
          
          
          
          <li id="bg-next">
            <img src="https://cdn.jsdelivr.net/gh/honjun/cdn@1.6/img/other/next-b.svg">
          </li>
        </div>
      </div>
    </div>
  </figure>
  
  <div id="video-container" style="display: none;">
    <video style="object-fit: fill" id="bgvideo" class="video" video-name="" src="" width="auto" preload="auto">
    </video>
    <div id="video-btn" class="loadvideo videolive">
    </div>
    <div id="video-add">
    </div>
    <div class="video-stu">
    </div>
  </div>
  
  <div class="headertop-down faa-float animated" onclick="headertop_down()">
    <span>
      <i class="fa fa-chevron-down" aria-hidden="true">
      </i>
    </span>
  </div>
</div>
    <div id="page" class="site wrapper">
      <header class="site-header no-select gizle sabit" role="banner">
 
  <div class="site-top">
    <div class="site-branding">
      <span class="site-title">
        <span class="logolink moe-mashiro">
          <a href="/">
            <span class="sakurasono">Conor_hua</span>
            <span class="shironeko"></span>
          </a>
        </span>
      </span>
    </div>
    <div class="searchbox search-form-submit">
      <i class="iconfont js-toggle-search iconsearch icon-search">
      </i>
    </div>
    <div id="show-nav" class="showNav mobile-fit">
      <div class="line line1">
      </div>
      <div class="line line2">
      </div>
      <div class="line line3">
      </div>
    </div>
    <div class="lower-cantiner">
      <div class="lower">
        <nav class="mobile-fit-control hide">
          <ul id="menu-new" class="menu">
            
              <li>
                <a href="/">
                  <span class="faa-parent animated-hover">
                    <i class="fa  fa-fort-awesome faa-shake" aria-hidden="true"></i>
                    首页
                  </span>
                </a>
                
              </li>
            
              <li>
                <a href="/archives">
                  <span class="faa-parent animated-hover">
                    <i class="fa  fa-archive faa-shake" aria-hidden="true"></i>
                    归档
                  </span>
                </a>
                
                  <ul class="sub-menu">
                    
                      <li>
                        <a href="/categories/%E6%8A%80%E6%9C%AF/">
                          <i class="fa fa-code" aria-hidden="true"></i>
                          技术
                        </a>
                      </li>
                    
                      <li>
                        <a href="/categories/%E5%B9%B2%E8%B4%A7/">
                          <i class="fa fa-plug" aria-hidden="true"></i>
                          干货
                        </a>
                      </li>
                    
                  </ul>
                
              </li>
            
              <li>
                <a href="javascript:;">
                  <span class="faa-parent animated-hover">
                    <i class="fa  fa-list-ul faa-vertical" aria-hidden="true"></i>
                    清单
                  </span>
                </a>
                
                  <ul class="sub-menu">
                    
                      <li>
                        <a href="/bangumis/">
                          <i class="fa fa-film faa-vertical" aria-hidden="true"></i>
                          番剧
                        </a>
                      </li>
                    
                      <li>
                        <a href="/categories/%E6%94%B6%E8%97%8F/">
                          <i class="fa fa-star" aria-hidden="true"></i>
                          收藏
                        </a>
                      </li>
                    
                  </ul>
                
              </li>
            
              <li>
                <a href="/tags/">
                  <span class="faa-parent animated-hover">
                    <i class="fa  fa-tags" aria-hidden="true"></i>
                    标签
                  </span>
                </a>
                
              </li>
            
              <li>
                <a href="javascript:;">
                  <span class="faa-parent animated-hover">
                    <i class="fa  fa-leaf faa-wrench" aria-hidden="true"></i>
                    关于
                  </span>
                </a>
                
                  <ul class="sub-menu">
                    
                      <li>
                        <a href="/about/">
                          <i class="fa fa-meetup" aria-hidden="true"></i>
                          我？
                        </a>
                      </li>
                    
                      <li>
                        <a href="/theme-sakura/">
                          <i class="fa iconfont icon-sakura" aria-hidden="true"></i>
                          主题
                        </a>
                      </li>
                    
                  </ul>
                
              </li>
            
              <li>
                <a href="/links/">
                  <span class="faa-parent animated-hover">
                    <i class="fa  fa-link faa-shake" aria-hidden="true"></i>
                    友人帐
                  </span>
                </a>
                
              </li>
            
          </ul>
        </nav>
      </div>
    </div>
  </div>
</header>

      <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/gh/xbclub/staticCDN@0.6/css/sharejs.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/xbclub/staticCDN@0.6/css/tocbot.css">
<div class="pattern-center-blank"></div>

  <div class="pattern-center single-center">
    <!-- 有配图默认渲染第一张 -->
    <div class="pattern-attachment-img">
        <img src="https://cdn.jsdelivr.net/gh/conorhua/asset/ima/upload.gif" data-src="https://cdn.jsdelivr.net/gh/conorhua/asset/ima/banner/wallhaven-l322ql.jpg" class="lazyload" onerror="imgError(this,3)" style="width: 100%; height: 100%; object-fit: cover; pointer-events: none;">
      </div>
    <header class="pattern-header single-header">
      <h1 class="entry-title">
      MySQL小结</h1>
      <p class="entry-census">
        <span>
          <a href="">
            <img src="https://cdn.jsdelivr.net/gh/conorhua/asset/ima/xiaomai.jpg">
          </a>
        </span>
        <span>
          <a href="">Conor_hua</a>
        </span>
        <span class="bull">
        ·</span>
        2021-7-25
        
      
        ·<span id="readcount"></span>次阅读
      
      </p>
    </header>
  </div>

<div id="content" class="site-content">
  <div id="primary" class="content-area">
    <main id="main" class="site-main" role="main">
      <article id="post-1" class="post-1 post type-post status-publish format-standard has-post-thumbnail hentry category-uncategorized">
        <div class="toc"></div>
        <!--<div class="toc-entry-content"> <!-- 套嵌目录使用（主要为了支援评论）-->
        
        <div class="entry-content">
          <p>本博客是MySQL复习的笔记。主要是记录方便日后回档。</p>
<p>本文参考文章如下：</p>
<p><a href="https://www.mysql.com/" target="_blank" rel="noopener">MySQL官网</a></p>
<h2 id="简介"><a href="#简介" class="headerlink" title="简介"></a>简介</h2><p>​        MySQL是一个关系型数据库，开源 免费，跨平台，支持分布式，现已归入Oracle旗下。</p>
<h2 id="使用"><a href="#使用" class="headerlink" title="使用"></a>使用</h2><p>先回顾一下基本SQL语句的使用。</p>
<h3 id="简单查询相关"><a href="#简单查询相关" class="headerlink" title="简单查询相关"></a>简单查询相关</h3><p>创建表：</p>
<pre><code class="sql">create table [if not exists] table_name (
    column-list
    #可加一些约束
)engine=table_type;</code></pre>
<p>if not exists是可选的，检查表是否已存在，若存在则不会创建新表，建议加上。</p>
<p>engine用来指定存储引擎，默认为InnoDB。</p>
<p>例如：</p>
<pre><code class="sql">create table if no exists test(
    test_id int not null auto_increment,
    test_name varchar(20) default null,
    test_age int ,
    primary key (test_id)
);</code></pre>
<p>删除表：</p>
<pre><code class="sql">drop table if exists test ;</code></pre>
<p>查询语句：</p>
<pre><code class="sql">SELECT 
    column_1, column_2, ...
FROM
    table_1
[INNER | LEFT |RIGHT] JOIN table_2 ON conditions
WHERE
    conditions
GROUP BY column_1
HAVING group_conditions
ORDER BY column_1
LIMIT offset, length;
#例如简单的select语句：
select test_id,test_name
from test;</code></pre>
<p>插入语句:</p>
<pre><code class="sql">INSERT INTO table(column1,column2...)
VALUES (value1,value2,...);
#例如:
insert into test(test_name,test_age)
values (&#39;小明&#39;, 18);
#插入多行
INSERT INTO table(column1,column2...)
VALUES (value1,value2,...),
       (value1,value2,...),
...;</code></pre>
<p>更新语句：</p>
<pre><code class="sql">UPDATE table_name 
SET 
    column_name1 = expr1,
    column_name2 = expr2,
    ...
WHERE
    condition;#忽略where会更新到所有行！！

#例如
update test 
set 
    name = &#39;大明&#39;
where 
    id = 1;
</code></pre>
<p>删除语句：</p>
<pre><code class="sql">DELETE FROM table_name
WHERE condition;

#例如
delete from test
where id = 1;</code></pre>
<p>where语句</p>
<table>
<thead>
<tr>
<th>操作符</th>
<th>描述</th>
</tr>
</thead>
<tbody><tr>
<td><code>=</code></td>
<td>等于，几乎任何数据类型都可以使用它。</td>
</tr>
<tr>
<td><code>&lt;&gt;</code> 或 <code>!=</code></td>
<td>不等于</td>
</tr>
<tr>
<td><code>&lt;</code></td>
<td>小于，通常使用数字和日期/时间数据类型。</td>
</tr>
<tr>
<td><code>&gt;</code></td>
<td>大于，</td>
</tr>
<tr>
<td><code>&lt;=</code></td>
<td>小于或等于</td>
</tr>
<tr>
<td><code>&gt;=</code></td>
<td>大于或等于</td>
</tr>
<tr>
<td>and</td>
<td>逻辑与</td>
</tr>
<tr>
<td>or</td>
<td>逻辑或</td>
</tr>
<tr>
<td>not</td>
<td>逻辑非</td>
</tr>
<tr>
<td>between …and</td>
<td>判断比较的值是否在某个范围</td>
</tr>
<tr>
<td>in</td>
<td>判断比较的值是否在某个集合</td>
</tr>
<tr>
<td>like</td>
<td>模糊比较 通配符 %表示可多个   _表示一个</td>
</tr>
<tr>
<td>is null</td>
<td>判断是否是null</td>
</tr>
</tbody></table>
<p>排序语句</p>
<p>order by</p>
<pre><code class="sql">SELECT  [DISTINCT] { *| 列名 | 表达式 [别名][,...] }
FROM    表名
[WHERE  条件]
[ORDER BY  {列名| 表达式| 列别名| 列序号} [ASC| DESC],…];
#asc升序 默认    desc降序
#order by用在select语句的最后</code></pre>
<p>limit子句</p>
<pre><code class="sql">SELECT 字段列表
FROM 数据源
LIMIT [start,]length;</code></pre>
<p>1．limit接受一个或两个整数参数。一个参数表示从0开始返回多少条数据</p>
<p> 2．start表示从第几行记录开始输出，length表示输出的记录行数。</p>
<p> 3．表中第一行记录的start值为0(不是 1)。</p>
<p>distinct关键字用来消除查询结果中的重复行</p>
<p>as用来取别名 省略也可</p>
<h3 id="多表查询相关"><a href="#多表查询相关" class="headerlink" title="多表查询相关"></a>多表查询相关</h3><p>用两个简单的表来测试:</p>
<p>student表：</p>
<p><img src="https://cdn.jsdelivr.net/gh/conorhua/asset/ima/blog/MySQL/student.png" alt="student"></p>
<p>class表:</p>
<p><img src="https://cdn.jsdelivr.net/gh/conorhua/asset/ima/blog/MySQL/class.png" alt="student"></p>
<p>笛卡尔积:</p>
<p>​    第一个表中的所有行与第二个表中的所有行都连接 ， 交叉连接。</p>
<pre><code class="sql">#无连接条件 或 连接条件无效
SELECT * FROM student,class ;</code></pre>
<p><img src="https://cdn.jsdelivr.net/gh/conorhua/asset/ima/blog/MySQL/1.png" alt="笛卡尔积"></p>
<p>查询结果有 6*4  = 24条记录</p>
<p>内连接：</p>
<p>返回的是所有匹配的记录。</p>
<pre><code class="sql">select * from student , class where student.cid = class.id;
select * from student CROSS JOIN class on student.cid = class.id;
select * from student INNER JOIN class on student.cid = class.id;</code></pre>
<p><img src="https://cdn.jsdelivr.net/gh/conorhua/asset/ima/blog/MySQL/2.png" alt="内连接"></p>
<p>外连接：</p>
<p>返回的是所有匹配的记录 以及主表中未匹配的记录，辅表所有列为null值。</p>
<pre><code class="sql">#左连接   右连接类似
select * from student left JOIN class on student.cid = class.id;</code></pre>
<p><img src="https://cdn.jsdelivr.net/gh/conorhua/asset/ima/blog/MySQL/3.png" alt="左外连接"></p>
<h3 id="常用函数"><a href="#常用函数" class="headerlink" title="常用函数"></a>常用函数</h3><p>分组函数：</p>
<ul>
<li><p>分组函数常用到以下五个函数：</p>
</li>
<li><ul>
<li>MIN</li>
<li>MAX</li>
</ul>
</li>
<li><ul>
<li>SUM</li>
<li>AVG</li>
</ul>
</li>
<li><ul>
<li>COUNT</li>
</ul>
</li>
</ul>
<pre><code class="sql">#MIN([DISTINCT | ALL] column | expression)

select min(age) from student ;
select max(age) from student ;
select avg(age) from student ;
select sum(age) from student ;
select count(*) from student ；</code></pre>
<p>使用group by子句创建数据组：</p>
<pre><code class="sql">SELECT    column, group_function(column)
FROM        table
[WHERE    condition]
[GROUP BY    group_by_expression]
[ORDER BY    column];

select cid,sum(age) from student 
group by cid;
#在SELECT列表中除了分组函数那些项，所有列都必须包含在GROUP BY 子句中。</code></pre>
<p><img src="https://cdn.jsdelivr.net/gh/conorhua/asset/ima/blog/MySQL/4.png" alt="分组"></p>
<pre><code class="sql">
#可以通过 HAVING 子句限制组
select cid,sum(age) from student 
group by cid
having cid is not null;

select cid,sum(age) from student 
group by cid
having sum(age)&gt;30;
</code></pre>
<p><img src="https://cdn.jsdelivr.net/gh/conorhua/asset/ima/blog/MySQL/5.png" alt="having"></p>
<p><img src="https://cdn.jsdelivr.net/gh/conorhua/asset/ima/blog/MySQL/6.png" alt="having"></p>
<p>还有更多的子查询以及复杂查询操作</p>
<p>to be continue。。。</p>
<p>如: </p>
<p>MySQL8.0后加入的row_number()函数</p>
<pre><code class="sql">ROW_NUMBER() OVER (&lt;partition_definition&gt; &lt;order_definition&gt;) ;
PARTITION BY &lt;expression&gt;,[{,&lt;expression&gt;}...] ;
ORDER BY &lt;expression&gt; [ASC|DESC],[{,&lt;expression&gt;}...] ;</code></pre>
<p>row_number()是一个窗口函数or分析函数，它可以从1开始为每一行分配一个序号。</p>
<p>partition by 子句将行分为更小的集合，用法于group by ；</p>
<p>order by 排序。</p>
<pre><code class="sql">SELECT name,age,cid,ROW_NUMBER() over (partition by cid order by age ) as &#39;排名&#39; FROM student;
</code></pre>
<p>row_number()序号不会重复</p>
<p><img src="https://cdn.jsdelivr.net/gh/conorhua/asset/ima/blog/MySQL/7.png" alt="row_number"></p>
<pre><code class="sql">SELECT name,age,cid,rank() over (partition by cid order by age ) as &#39;排名&#39; FROM student;
</code></pre>
<p>rank()序号会重复，不连续</p>
<p><img src="https://cdn.jsdelivr.net/gh/conorhua/asset/ima/blog/MySQL/8.png" alt="rank"></p>
<pre><code class="sql">SELECT name,age,cid,dense_rank() over (partition by cid order by age ) as &#39;排名&#39; FROM student;
</code></pre>
<p>dense_rank()序号会重复，且连续</p>
<p><img src="https://cdn.jsdelivr.net/gh/conorhua/asset/ima/blog/MySQL/9.png" alt="rank"></p>
<h2 id="一些概念"><a href="#一些概念" class="headerlink" title="一些概念:"></a>一些概念:</h2><h3 id="数据库三范式："><a href="#数据库三范式：" class="headerlink" title="数据库三范式："></a>数据库三范式：</h3><ul>
<li>数据库设计应该遵循三范式</li>
<li>第一范式：原子性<ul>
<li>列不可再分</li>
<li>反例： 一个字段是联系方式：里面放了 电话，邮箱</li>
<li>正例：分为两个字段：电话，邮箱</li>
</ul>
</li>
<li>第二范式：唯一性<ul>
<li>属性应全部依赖于主键，不应该存在部分依赖，如下面学分部分依赖于课程号</li>
<li>反例：学号，课程号，成绩，学分 </li>
<li>正例：应该分为两个表<ul>
<li>学生表：学号，姓名</li>
<li>课程表：课程号，学分</li>
</ul>
</li>
</ul>
</li>
<li>第三范式：冗余性<ul>
<li>不应该存在依赖传递</li>
<li>应通过外键联系</li>
<li>反例： 员工表： 员工编号，姓名，部门编号，部门名称</li>
<li>正例：<ul>
<li>员工表：  员工编号，姓名，部门编号，</li>
<li>部门表：   部门编号，部门名称</li>
</ul>
</li>
</ul>
</li>
</ul>
<h3 id="MySQL中有关权限的表："><a href="#MySQL中有关权限的表：" class="headerlink" title="MySQL中有关权限的表："></a>MySQL中有关权限的表：</h3><p>​        user：用户账号、全局权限</p>
<p>　　db：库级别权限</p>
<p>　　host：废弃</p>
<p>　　tables_priv：表级别权限</p>
<p>　　colums_priv：列级别权限</p>
<p>　　procs_priv：存储过程和存储函数相关的权限</p>
<p>　　proxies_priv：代理用户权限</p>
<p>权限级别：</p>
<p>　    服务管理类：super</p>
<p>　　库：CREATE</p>
<p>　　表：DELETE、ALTER</p>
<p>　　列：INSERT、SELECT、UPDATE</p>
<p>　　更多级别可参考MySQL官方文档</p>
<h3 id="MySQL常见的数据类型："><a href="#MySQL常见的数据类型：" class="headerlink" title="MySQL常见的数据类型："></a>MySQL常见的数据类型：</h3><ul>
<li>整数类型<ul>
<li>tinyInt              1bytes</li>
<li>smallInt           2bytes</li>
<li>mediumInt     3bytes</li>
<li>int                4bytes</li>
<li>bigInt     8bytes</li>
</ul>
</li>
<li>实数类型<ul>
<li>float   4bytes</li>
<li>double 8bytes</li>
<li>decimal  精准的数据类型 float double是非精准的保存的是近似值</li>
</ul>
</li>
<li>字符串类型<ul>
<li>char 字符串</li>
<li>varchar 可变字符串</li>
<li>text 长文本</li>
<li>blob 二进制文本数据</li>
</ul>
</li>
<li>日期与时间类型<ul>
<li>date 日期</li>
<li>time  时间</li>
<li>year 月份</li>
<li>datetime  日期和时间</li>
<li>timestamp 时间戳 也是日期和时间</li>
</ul>
</li>
</ul>
<p>datetime和timestamp</p>
<p>timestamp所能存储的时间范围为：’1970-01-01 00:00:01.000000’ 到 ‘2038-01-19 03:14:07.999999’。</p>
<p>datetime所能存储的时间范围为：’1000-01-01 00:00:00.000000’ 到 ‘9999-12-31 23:59:59.999999’。</p>
<p>timestamp能自动初始化和更新，与时区相关</p>
<p>char和varchar</p>
<p>char后在后面补空格，varchar会用一字节存储长度</p>
<p>对于短数据用char更好，省空间</p>
<p>对于长度分布不均的用varchar好</p>
<p>对于经常变更的用char 不容易产生碎片空间</p>
<h3 id="存储引擎"><a href="#存储引擎" class="headerlink" title="存储引擎"></a>存储引擎</h3><p>InnoDB：提供了对数据库ACID事务的支持，提供了行级锁和外键的约束</p>
<p>MyISAM：不支持以上</p>
<p>InnoDB 是聚集索引，MyISAM 是非聚集索引。</p>
<p>选择：</p>
<p>没有特别需求，一般使用默认的InnorDB。</p>
<p>对于以读写插入为主的应用程序，比如博客系统，新闻网站，选择MyISAM</p>
<p>InnoDB引擎4大特性</p>
<ul>
<li>插入缓存</li>
<li>二次写</li>
<li>自适应哈希索引</li>
<li>预读</li>
</ul>
<h2 id="索引"><a href="#索引" class="headerlink" title="索引"></a>索引</h2><p>索引是一种特殊的文件，包含这对数据表里所有记录的引用指针。</p>
<p>索引是一种数据结构，一个排序的数据结构，以协助快速查询。</p>
<p>通俗的说，索引相当于目录。</p>
<p>常见使用场景</p>
<ul>
<li>where</li>
<li>order by</li>
<li>join</li>
</ul>
<p>优缺点：</p>
<ul>
<li>大大加快数据的检索速度，主要作用。</li>
<li>通过使用索引，可以在查询的过程中，使用优化隐藏器，提高系统的性能。</li>
<li>创建索引和维护索引需要耗时，对表数据的增加，删除和修改的时候都需要动态的维护索引。</li>
<li>索引需要占用物理空间</li>
</ul>
<h3 id="索引类型："><a href="#索引类型：" class="headerlink" title="索引类型："></a>索引类型：</h3><ul>
<li>普通索引<ul>
<li>最基本的索引，没有什么限制，仅加速查询</li>
</ul>
</li>
<li>唯一索引<ul>
<li>与普通索引类似，但索引列的值必须唯一，可以为空值</li>
</ul>
</li>
<li>主键索引<ul>
<li>特殊的唯一索引，不允许有空值，一个表一个</li>
</ul>
</li>
<li>组合索引<ul>
<li>组合索引是指在多个字段是创建索引，只有在查询条件中使用了创建索引时的第一个字段，索引才会被使用，使用时遵循最左前缀原则</li>
</ul>
</li>
<li>全文索引<ul>
<li>目前搜索引擎使用的一种关键技术</li>
</ul>
</li>
</ul>
<h3 id="索引的数据结构"><a href="#索引的数据结构" class="headerlink" title="索引的数据结构"></a>索引的数据结构</h3><p>索引的数据结构和具体的存储引擎的实现有关，使用较多的索引有hash索引和B+树索引。</p>
<p>InnoDB存储引擎的默认索引实现为B+树索引。</p>
<p>对于哈希索引来说，底层的数据结构就是哈希表，因此在绝大 多数需求 为单条记录查询的时候，可以选择哈希索引，查询性能最快；其余大部分场景， 建议选择BTree索引。</p>
<h3 id="基本原理"><a href="#基本原理" class="headerlink" title="基本原理"></a>基本原理</h3><p>索引用来快速地寻找那些具有特定值的记录。如果没有索引，一般来说执行查询 时遍历整张表。 索引的原理很简单，就是把无序的数据变成有序的查询</p>
<ol>
<li>把创建了索引的列的内容进行排序</li>
<li>对排序结果生成倒排表 </li>
<li>在倒排表内容上拼上数据地址链 </li>
<li>在查询的时候，先拿到倒排表内容，再取出数据地址链，从而拿到具体数据</li>
</ol>
<h3 id="创建索引的原则："><a href="#创建索引的原则：" class="headerlink" title="创建索引的原则："></a>创建索引的原则：</h3><ul>
<li>最左前缀匹配原则，组合索引非常重要的原则，mysql会一直向右匹配直到遇 到范围查询(&gt;、&lt;、between、like)就停止匹配，比如a = 1 and b = 2 and c &gt; 3 and d = 4 如果建立(a,b,c,d)顺序的索引，d是用不到索引的，如果建立(a,b,d,c)的 索引则都可以用到，a,b,d的顺序可以任意调整。</li>
<li>较频繁作为查询条件的字段才去创建索引</li>
<li>更新频繁字段不适合创建索引</li>
<li>若是不能有效区分数据的列不适合做索引列(如性别，男女未知，最多也就三 种，区分度实在太低)</li>
<li>尽量的扩展索引，不要新建索引。比如表中已经有a的索引，现在要加(a,b) 的索引，那么只需要修改原来的索引即可。</li>
<li>定义有外键的数据列一定要建立索引</li>
<li>对于那些查询中很少涉及的列，重复值比较多的列不要建立索引。</li>
</ul>
<h2 id="数据库事务"><a href="#数据库事务" class="headerlink" title="数据库事务"></a>数据库事务</h2><h3 id="事务特征ACID"><a href="#事务特征ACID" class="headerlink" title="事务特征ACID"></a>事务特征ACID</h3><ul>
<li>原子性：要么全部执行，要么都不执行。</li>
<li>一致性：执行事务前后，数据保持一致</li>
<li>隔离性：并发访问数据库时，多个事务不被其他事务干扰，各事务之间独立</li>
<li>持久性：一个事务被提交之后，它对数据库的改变是持久的，即使发生故障也不应该对提交结果造成影响。</li>
</ul>
<h3 id="隔离级别"><a href="#隔离级别" class="headerlink" title="隔离级别"></a>隔离级别</h3><p>脏读？不可重复读？幻读？</p>
<ul>
<li>脏读：事务1更新了数据A，事务2读取了数据A，但是事务1 rollback了，那么事务2读取的数据就是不正确的。</li>
<li>不可重复读：一个事务在两次查询中的数据不一致，可能是两次查询中间插入了另一个事务更新了原来的数据。</li>
<li>幻读：在一个事务的两次查询中，查询到的数据条数不一致，例如有一个事务查询了几行数据，而另一个事务却在此时插入了新的几行数据，先前的事务 在接下来的查询中，就会发现有几列数据是它先前所没有的。</li>
</ul>
<p>数据库定义了4中不同的事务隔离级别</p>
<p>Read uncommitted、Read committed、Repeatable read、Serializab</p>
<ul>
<li>读未提交：最低的隔离级别</li>
<li>读已提交：允许读取事务已经提交的数据，可防止脏读</li>
<li>可重复读：对同一字段的多次读取结果唯一，可防止脏读和不可重复读</li>
<li>可串行化：所有事务依次执行，防止脏读，不可重复读，幻读。</li>
</ul>
<p>MySQL默认使用repeatable read</p>
<h3 id="事务与锁"><a href="#事务与锁" class="headerlink" title="事务与锁"></a>事务与锁</h3><ul>
<li><p>在Read Uncommitted级别下，读取数据不需要加共享锁，这样就不会跟被修改 的数据上的排他锁冲突 </p>
</li>
<li><p>在Read Committed级别下，读操作需要加共享锁，但是在语句执行完以后释放 共享锁；</p>
</li>
<li><p>在Repeatable Read级别下，读操作需要加共享锁，但是在事务提交之前并不释 放共享锁，也就是必须等待事务执行完毕以后才释放共享锁。</p>
</li>
<li><p>SERIALIZABLE 是 限制性最强的隔离级别，因为该级别锁定整个范围的键，并一直持有锁，直到事务完成。</p>
</li>
</ul>

        </div>
        <!-- .entry-content -->
        
        <p></p>
          
        <div style="text-align:center; width: 100%" class="social-share share-mobile" data-disabled="diandian, tencent"></div>
        <footer class="post-footer">
          <div class="post-lincenses"><a href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh" target="_blank" rel="nofollow"><i class="fa fa-creative-commons" aria-hidden="true"></i> 知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议</a></div>
          <div class="post-tags">
            <div class="tag-cloud">
              <div class="tag-cloud-title">
              </div>
              <div class="tag-cloud-tags">
              <a href="/tags/CDN/" style="font-size: 10px; color: #f38181">CDN</a> <a href="/tags/Chrome/" style="font-size: 10px; color: #f38181">Chrome</a> <a href="/tags/Collection/" style="font-size: 10px; color: #f38181">Collection</a> <a href="/tags/ElasticSearch/" style="font-size: 10px; color: #f38181">ElasticSearch</a> <a href="/tags/IO%E6%B5%81/" style="font-size: 10px; color: #f38181">IO流</a> <a href="/tags/JVM/" style="font-size: 10px; color: #f38181">JVM</a> <a href="/tags/Java/" style="font-size: 16.67px; color: #b4c1b8">Java</a> <a href="/tags/Linux/" style="font-size: 10px; color: #f38181">Linux</a> <a href="/tags/MySQL/" style="font-size: 10px; color: #f38181">MySQL</a> <a href="/tags/OIS/" style="font-size: 10px; color: #f38181">OIS</a> <a href="/tags/Redis/" style="font-size: 13.33px; color: #d4a19c">Redis</a> <a href="/tags/SQL/" style="font-size: 10px; color: #f38181">SQL</a> <a href="/tags/Springboot/" style="font-size: 10px; color: #f38181">Springboot</a> <a href="/tags/TCP-IP/" style="font-size: 10px; color: #f38181">TCP/IP</a> <a href="/tags/Tomcat/" style="font-size: 10px; color: #f38181">Tomcat</a> <a href="/tags/aop/" style="font-size: 10px; color: #f38181">aop</a> <a href="/tags/bili/" style="font-size: 10px; color: #f38181">bili</a> <a href="/tags/eclipse/" style="font-size: 10px; color: #f38181">eclipse</a> <a href="/tags/git/" style="font-size: 10px; color: #f38181">git</a> <a href="/tags/github/" style="font-size: 13.33px; color: #d4a19c">github</a> <a href="/tags/ioc/" style="font-size: 10px; color: #f38181">ioc</a> <a href="/tags/java/" style="font-size: 20px; color: #95e1d3">java</a> <a href="/tags/jsdelivr/" style="font-size: 10px; color: #f38181">jsdelivr</a> <a href="/tags/oracle/" style="font-size: 10px; color: #f38181">oracle</a> <a href="/tags/spring/" style="font-size: 13.33px; color: #d4a19c">spring</a> <a href="/tags/sring/" style="font-size: 10px; color: #f38181">sring</a> <a href="/tags/vscode/" style="font-size: 10px; color: #f38181">vscode</a> <a href="/tags/web/" style="font-size: 10px; color: #f38181">web</a> <a href="/tags/%E5%8F%8D%E5%B0%84/" style="font-size: 10px; color: #f38181">反射</a> <a href="/tags/%E5%A4%9A%E7%BA%BF%E7%A8%8B/" style="font-size: 10px; color: #f38181">多线程</a> <a href="/tags/%E5%AE%9E%E4%B9%A0/" style="font-size: 10px; color: #f38181">实习</a> <a href="/tags/%E6%8E%92%E5%BA%8F/" style="font-size: 10px; color: #f38181">排序</a> <a href="/tags/%E6%B3%A8%E8%A7%A3/" style="font-size: 10px; color: #f38181">注解</a> <a href="/tags/%E6%B4%BE%E5%A4%A7%E6%98%9F/" style="font-size: 10px; color: #f38181">派大星</a> <a href="/tags/%E7%BD%91%E7%BB%9C/" style="font-size: 10px; color: #f38181">网络</a>
              </div>
            </div>
          </div>
          <div class="post-share">
            <div class="social-share sharehidden share-component"></div>
            <i class="iconfont show-share icon-forward"></i>
          </div>
        </footer><!-- .entry-footer -->
      </article>
      <!-- #post-## -->
      <div class="toc" style="background: none;"></div>
      <section class="post-squares nextprev">
        
          
            <div class="post-nepre half previous">
          
            <a href="/posts/62d904b9.html" rel="prev">
              <div class="background">
<!--                <img class="lazyload" src="https://cdn.jsdelivr.net/gh/conorhua/asset/ima/upload.gif" data-src="https://cdn.jsdelivr.net/gh/conorhua/asset/ima/banner/wallhaven-9mr9zw.png" style="width: 100%; height: 100%; object-fit: cover; pointer-events: none;" onerror="imgError(this,3)" src="https://cdn.jsdelivr.net/gh/conorhua/asset/ima/banner/wallhaven-9mr9zw.png">-->
                
                <img class="lazyload" src="https://cdn.jsdelivr.net/gh/conorhua/asset/ima/upload.gif" data-src="https://cdn.jsdelivr.net/gh/conorhua/asset/ima/banner/wallhaven-9mr9zw.png" style="width: 100%; height: 100%; object-fit: cover; pointer-events: none;" onerror="imgError(this,3)" >
              </div>
              <span class="label">
              Previous Post</span>
              <div class="info">
                <h3>
                Spring框架</h3>
                <hr>
              </div>
            </a>
          </div>
        
        
          
            <div class="post-nepre half next">
          
            <a href="/posts/41268e44.html" rel="next">
              <div class="background">
                
                <img class="lazyload" src="https://cdn.jsdelivr.net/gh/conorhua/asset/ima/upload.gif" data-src="https://cdn.jsdelivr.net/gh/conorhua/asset/ima/banner/wallhaven-wyzxvr.jpg" style="width: 100%; height: 100%; object-fit: cover; pointer-events: none;" onerror="imgError(this,3)" >
              </div>
              <span class="label">
              Next Post</span>
              <div class="info">
                <h3>
                注解与反射</h3>
                <hr>
              </div>
            </a>
          </div>
        
      </section>
      
      <section class="author-profile">
        <div class="info" itemprop="author" itemscope="" itemtype="https://schema.org/Person">
          <a href="" class="profile gravatar"><img src="https://cdn.jsdelivr.net/gh/conorhua/asset/ima/xiaomai.jpg" itemprop="image" alt="Conor_hua" height="70" width="70"></a>
          <div class="meta">
            <span class="title">Author</span>
            <h3 itemprop="name">
            <a href="" itemprop="url" rel="author">Conor_hua</a>
            </h3>
          </div>
        </div>
        <hr>
        <p><i class="iconfont icon-write"></i></p>
      </section>
    </main><!-- #main -->
  </div><!-- #primary -->
</div>


    </div>    
    <div class="ins-search">
    <div class="ins-search-mask"></div>
    <div class="ins-search-container">
        <div class="ins-input-wrapper">
            <input type="text" class="ins-search-input" placeholder="请输入关键词..."/>
            <span class="ins-close ins-selectable"><i class="fa fa-times-circle"></i></span>
        </div>
        <div class="ins-section-wrapper">
            <div class="ins-section-container"></div>
        </div>
    </div>
</div>
<script>
(function (window) {
    var INSIGHT_CONFIG = {
        TRANSLATION: {
            POSTS: '文章',
            // PAGES: '页面',
            CATEGORIES: '分类',
            TAGS: '标签',
        },
        ROOT_URL: '/',
        CONTENT_URL: '/content.json',
    };
    window.INSIGHT_CONFIG = INSIGHT_CONFIG;
})(window);
</script>
    <!-- <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2021 Conor_hua<br>
      powered_by <a href="http://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer> -->
<footer id="colophon" class="site-footer" role="contentinfo">
    <div class="site-info">
        <div class="footertext">
            <div class="img-preload">
                <img src="https://cdn.jsdelivr.net/gh/honjun/cdn@1.6/img/other/wordpress-rotating-ball-o.svg">
                <img src="https://cdn.jsdelivr.net/gh/honjun/cdn@1.6/img/other/disqus-preloader.svg">
            </div>
            
            <p>本站总访问量：<a id="allcount"></a></p>
            <p style="color: #666666;">it you can dream it you can do it</p>
            
                <p id="momk" style="font-family: 'Ubuntu', sans-serif;color: #b9b9b9;"></p>
            
        </div>
        <div class="footer-device">
            <p style="font-family: 'Ubuntu', sans-serif;">
 <span style=""> <a 
                         style="color: 	#FF69B4;;text-decoration: underline dotted rgba(0, 0, 0, .1);">Conor_hua</a> <i
             class="iconfont icon-sakura rotating" style="color: #ffc0cb;display:inline-block"></i> Theme <a
             href="https://github.com/xbclub/Hexo-theme-sakura" target="_blank"
             style="color: #FF69B4;;text-decoration: underline dotted rgba(0, 0, 0, .1);">Sakura</a><a
             
             style="color: #b9b9b9;;text-decoration: underline dotted rgba(0, 0, 0, .1);">, Powered by</a><a
             href="https://github.com/hexojs/hexo" target="_blank"
             style="color: #FF69B4;;text-decoration: underline dotted rgba(0, 0, 0, .1);"> Hexo</a>
        </span>
            </p>
        </div>
    </div><!-- .site-info -->
    <!--壁纸切换-->
  <div class="skin-menu no-select" id="mainskin"  style="position: fixed">
    <div class="theme-controls row-container">
        <ul class="menu-list">
            <li id="white-bg"> <i class="fa fa-television" aria-hidden="true"></i></li>
            <li id="sakura-bg"> <i class="iconfont icon-sakura"></i></li>
            <li id="gribs-bg"> <i class="fa fa-slack" aria-hidden="true"></i></li>
            <li id="KAdots-bg"> <i class="iconfont icon-dots"></i></li>
            <li id="totem-bg"> <i class="fa fa-optin-monster" aria-hidden="true"></i></li>
            <li id="pixiv-bg"> <i class="iconfont icon-pixiv"></i></li>
            <li id="bing-bg"> <i class="iconfont icon-bing"></i></li>
            <li id="dark-bg"> <i class="fa fa-moon-o" aria-hidden="true"></i></li>
        </ul>
    </div>
    <div class="font-family-controls row-container">
        <button type="button" class="control-btn-serif selected" data-mode="serif" onclick="mashiro_global.font_control.change_font()">Serif</button>
        <button type="button" class="control-btn-sans-serif" data-mode="sans-serif" onclick="mashiro_global.font_control.change_font()">Sans Serif</button>
    </div>
</div>   
<canvas id="night-mode-cover"></canvas> 
  <div class="changeSkin-gear no-select">
    <div class="keys" id="setbtn"> <span id="open-skinMenu"> 切换壁纸 | SCHEME TOOL 
      &nbsp;<i class="iconfont icon-gear inline-block rotating"></i> </span></div>
</div><!--skin.end-->
</footer>


<!--<script src="https://cdn.jsdelivr.net/gh/xbclub/staticCDN@0.7/js/tocbot.min.js"></script>-->

<script type="text/javascript" src="https://cdn.jsdelivr.net/gh/xbclub/staticCDN@0.8/js/lib.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/clipboard@2/dist/clipboard.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/gh/xbclub/staticCDN@0.8/js/InsightSearch.js"></script>
<script type="text/javascript"
        src="https://cdn.jsdelivr.net/gh/xbclub/staticCDN@0.8/js/jquery.fancybox.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/gh/xbclub/staticCDN@0.8/js/zoom.min.js"></script>

<script type="text/javascript" src="https://cdn.jsdelivr.net/gh/xbclub/staticCDN@1.2/js/sakura-app.js"></script>
    
<script src="https://cdn.jsdelivr.net/gh/xbclub/staticCDN@0.8/js/av-min.js"></script>
<script src='https://cdn.jsdelivr.net/gh/xbclub/staticCDN@0.8/js/Valine.min.js'></script>
<script src="https://cdn.jsdelivr.net/gh/xbclub/staticCDN@0.8/js/botui.js"></script>
<!-- 不蒜子 网页计数器 -->

      
       <script>
  fetch('https://counts.42cloud.cn/api/counts.html')
        .then(response => response.json())
        .then(data => {
              if (document.getElementById("readcount")) {
                document.getElementById("readcount").innerHTML=data.Count;
            }
            if (document.getElementById("allcount")){
                document.getElementById("allcount").innerHTML=data.Allcount;
            }
        })
        .catch(err => console.error(err))
</script>
      
<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/tocbot/4.4.2/tocbot.min.js"></script> -->
<script type="text/javascript">
    /* <![CDATA[ */
    if (/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)) {
        var Poi = {
            "pjax": "1",
            "movies": {"url": "https://cdn.jsdelivr.net/gh/honjun/hojun@1.2", "name": "Unbroken.mp4", "live": "close"},
            "windowheight": "fixed",
            "codelamp": "close",
            "ajaxurl": "",
            "order": "asc",
            "formpostion": "bottom"
        };
    } else {
        var Poi = {
            "pjax": "1",
            "movies": {"url": "https://cdn.jsdelivr.net/gh/honjun/hojun@1.2", "name": "Unbroken.mp4", "live": "open"},
            "windowheight": "auto",
            "codelamp": "close",
            "ajaxurl": "",
            "order": "asc",
            "formpostion": "bottom"
        };
    }
    /* ]]> */

</script>
<script>
    $(document).ready(function () {
        if ($(".toc").length > 0 && document.body.clientWidth > 1200) {
            if ($(".pattern-center").length > 0) { //有图的情况
                tocbot.init({
                    // Where to render the table of contents.
                    tocSelector: '.toc', // 放置目录的容器
                    // Where to grab the headings to build the table of contents.
                    contentSelector: '.entry-content', // 正文内容所在
                    // Which headings to grab inside of the contentSelector element.
                    scrollSmooth: true,
                    headingSelector: 'h1, h2, h3, h4, h5', // 需要索引的标题级别
                    headingsOffset: -400,
                    scrollSmoothOffset: -85
                });
            } else {
                tocbot.init({
                    // Where to render the table of contents.
                    tocSelector: '.toc', // 放置目录的容器
                    // Where to grab the headings to build the table of contents.
                    contentSelector: '.entry-content', // 正文内容所在
                    // Which headings to grab inside of the contentSelector element.
                    scrollSmooth: true,
                    headingSelector: 'h1, h2, h3, h4, h5', // 需要索引的标题级别
                    headingsOffset: -85,
                    scrollSmoothOffset: -85
                });
            }
            var offsetTop = $('.toc').offset().top - 95;
            window.onscroll = function () {
                var scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
                if (scrollTop >= offsetTop) {
                    $('.toc').addClass('toc-fixed');
                } else {
                    $('.toc').removeClass('toc-fixed');
                }
            }
        }
    });

</script>
<span style="color: #FF69B4 ;padding-left: 20px;">
    <i class="fa fa-clock-o" aria-hidden="true"></i>
    <span id="time" align="center">载入时间中...</span>

    <script type="text/javascript">
        function NewDate(str) {
            str = str.split('-');
            var date = new Date();
            date.setUTCFullYear(str[0], str[1] - 1, str[2]);
            date.setUTCHours(0, 0, 0, 0);
            return date;
        }

        function momxc() {
            var birthDay = NewDate("2020-7-16");
            var today = new Date();
            var timeold = today.getTime() - birthDay.getTime();
            var sectimeold = timeold / 1000
            var secondsold = Math.floor(sectimeold);
            var msPerDay = 24 * 60 * 60 * 1000;
            var e_daysold = timeold / msPerDay;
            var daysold = Math.floor(e_daysold);
            var e_hrsold = (daysold - e_daysold) * -24;
            var hrsold = Math.floor(e_hrsold);
            var e_minsold = (hrsold - e_hrsold) * -60;
            var minsold = Math.floor((hrsold - e_hrsold) * -60);
            var seconds = Math.floor((minsold - e_minsold) * -60).toString();
            document.getElementById("momk").innerHTML = "本小破站已勉强维持生活" + daysold + "天" + hrsold + "小时" + minsold + "分" + seconds + "秒";
            setTimeout(momxc, 1000);
        }
        
        momxc();
    </script>


</span>


    <div class="openNav no-select" style="height: 50px;">
      <div class="iconflat no-select" style="width: 50px; height: 50px;">
        <div class="icon"></div>
      </div>
      <div class="site-branding search-form-submit">
        <i class="iconfont js-toggle-search iconsearch icon-search"></i>
      </div>
    </div>
  </section>
  <div id="mo-nav" class="">
  <div class="m-avatar">
    <img src="https://cdn.jsdelivr.net/gh/conorhua/asset/ima/xiaomai.jpg">
  </div>
  <p style="text-align: center; color: #333; font-weight: 900; font-family: 'Ubuntu', sans-serif; letter-spacing: 1.5px">Conor_hua</p>
  <p style="text-align: center; word-spacing: 20px;">
    
  </p>
  <ul id="menu-new-1" class="menu">
    
      <li>
        <a href="/">
          <span class="faa-parent animated-hover">
            <i class="fa  fa-fort-awesome faa-shake" aria-hidden="true"></i>
            首页
          </span>
        </a>
        
      </li>
    
      <li>
        <a href="/archives">
          <span class="faa-parent animated-hover">
            <i class="fa  fa-archive faa-shake" aria-hidden="true"></i>
            归档
          </span>
        </a>
        
          <ul class="sub-menu">
            
              <li>
                <a href="/categories/%E6%8A%80%E6%9C%AF/">
                  <i class="fa fa-code" aria-hidden="true"></i>
                  技术
                </a>
              </li>
            
              <li>
                <a href="/categories/%E5%B9%B2%E8%B4%A7/">
                  <i class="fa fa-plug" aria-hidden="true"></i>
                  干货
                </a>
              </li>
            
          </ul>
        
      </li>
    
      <li>
        <a href="javascript:;">
          <span class="faa-parent animated-hover">
            <i class="fa  fa-list-ul faa-vertical" aria-hidden="true"></i>
            清单
          </span>
        </a>
        
          <ul class="sub-menu">
            
              <li>
                <a href="/bangumis/">
                  <i class="fa fa-film faa-vertical" aria-hidden="true"></i>
                  番剧
                </a>
              </li>
            
              <li>
                <a href="/categories/%E6%94%B6%E8%97%8F/">
                  <i class="fa fa-star" aria-hidden="true"></i>
                  收藏
                </a>
              </li>
            
          </ul>
        
      </li>
    
      <li>
        <a href="/tags/">
          <span class="faa-parent animated-hover">
            <i class="fa  fa-tags" aria-hidden="true"></i>
            标签
          </span>
        </a>
        
      </li>
    
      <li>
        <a href="javascript:;">
          <span class="faa-parent animated-hover">
            <i class="fa  fa-leaf faa-wrench" aria-hidden="true"></i>
            关于
          </span>
        </a>
        
          <ul class="sub-menu">
            
              <li>
                <a href="/about/">
                  <i class="fa fa-meetup" aria-hidden="true"></i>
                  我？
                </a>
              </li>
            
              <li>
                <a href="/theme-sakura/">
                  <i class="fa iconfont icon-sakura" aria-hidden="true"></i>
                  主题
                </a>
              </li>
            
          </ul>
        
      </li>
    
      <li>
        <a href="/links/">
          <span class="faa-parent animated-hover">
            <i class="fa  fa-link faa-shake" aria-hidden="true"></i>
            友人帐
          </span>
        </a>
        
      </li>
    
  </ul>
  <p style="text-align: center; font-size: 13px; color: #b9b9b9;">&copy 2019 hexo-sakura</p>
</div>
<button onclick="topFunction()" class="mobile-cd-top" id="moblieGoTop" title="Go to top" style="display: none;"><i class="fa fa-chevron-up" aria-hidden="true"></i></button>
  
</body>
<script src="https://cdn.jsdelivr.net/gh/conorhua/asset/js/noSomeKey.js"></script>
</html>